package com.flyweight;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Main {
    public static void main(String[] args){
        BulletPool bp = new BulletPool();
        for(int i = 0; i < 10; i ++){
            Bullet b = bp.getButtet();
            System.out.println(b);
        }
    }
    static class BulletPool{
        List<Bullet> bullets = new ArrayList<>();
        {
            for(int i = 0; i < 5; i ++){
                bullets.add(new Bullet());
            }
        }

        public Bullet getButtet() {
            for (int i = 0; i < bullets.size(); i++) {
                Bullet b = bullets.get(i);
                if (!b.living) return b;
            }
            return new Bullet();
        }
    }
}

class Bullet{
    public UUID id = UUID.randomUUID();
    boolean living = true;

    @Override
    public String toString() {
        return "Bullet{" +
                "id=" + id +
                ", living=" + living +
                '}';
    }
}